//
//  DistanceCell.m
//  Project6
//
//  Created by ToanDK on 11/18/12.
//  Copyright (c) 2012 DungNP. All rights reserved.
//

#import "DistanceCell.h"

@implementation DistanceCell
@synthesize txtSliderValueDisplay;
@synthesize slider;
@synthesize segmentation;
@synthesize steper;
@synthesize textField;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
       
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    [self.contentView setBackgroundColor:[UIColor clearColor]];
    [self setBackgroundView:nil];
    [self setBackgroundColor:[UIColor clearColor]];
    
    //textField.text = [NSString stringWithFormat:@"%0.02f", 0.0f];
    steper.transform = CGAffineTransformMakeScale(0.3, 0.3);
    steper.hidden = YES;
}
-(void)sliderChange:(id)sender
{
    int value = (int) (((UISlider*)sender).value);
    [textField setText:[NSString stringWithFormat:@"%0.02f",0.25f*value]];
}

#pragma UITextFieldDelegate 
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    
    if ([string isEqualToString:@"."] ) {
        if ([textField.text rangeOfString:@"."].length > 0) {
            return NO;
        }
    }
    
    NSString * tfStr = [textField.text stringByAppendingString:string];
    int value = [tfStr integerValue];
    
    if (value > slider.maximumValue) {
        value =slider.maximumValue;
        slider.value = value/0.25;
        return NO;
    }
    slider.value = value/0.25;
    return YES;
}

@end
